package com.admin.service.booktypeservice;


import com.admin.dao.booktypedao.BookTypeDaoImpl;
import com.admin.dao.booktypedao.BookTypeDaoInF;
import com.pojo.BookTypeBean;
import com.utils.DBUtil;

import java.sql.Connection;
import java.sql.SQLException;

public class BookTypeService implements BookTypeServiceInF{
    BookTypeDaoInF bookTypeDao;
    public BookTypeService(){
        bookTypeDao=new BookTypeDaoImpl();

    }


    @Override
    public boolean insertBookType(BookTypeBean typeBean) {

        boolean bool = false;
        Connection conn = null;

        try {
            conn = DBUtil.getConn();
            conn.setAutoCommit(false);////开启了 事务
            String sql="INSERT into booktype VALUES(null,?,?)";

            bool = bookTypeDao.InsertInfo(sql, conn, typeBean);

            if (bool) {
                conn.commit();
            } else {
                conn.rollback();
            }

        } catch (SQLException e) {
            e.printStackTrace();
            try {
                conn.rollback();
            } catch (SQLException ex) {
                ex.printStackTrace();
            }

        } finally {
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }

        }
        return bool;

    }
}
